package com.wlw.eye.adapter

import android.content.Intent
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.wlw.eye.R
import com.wlw.eye.mvp.model.bean.FindBean
import com.wlw.eye.ui.FindDetailActivity
import com.wlw.eye.utils.ImageLoadUtils
import kotlinx.android.synthetic.main.item_find.view.*

class FindAdapter( var list: MutableList<FindBean>?) : RecyclerView.Adapter<BaseHolder>() {
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BaseHolder {
        return BaseHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_find, parent, false))
    }

    override fun getItemCount(): Int = list?.size ?: 0
    override fun onBindViewHolder(holder: BaseHolder, position: Int) {
        bindView(holder.itemView, list?.get(position))
    }

    private fun bindView(itemView: View, bean: FindBean?) {
        bean?.bgPicture?.let { ImageLoadUtils.display(itemView.context, itemView.iv_photo, it) }
        itemView.tv_title.text = bean?.name
        itemView.setOnClickListener {
            var name = bean?.name ?: ""
            val intent = Intent(itemView.context, FindDetailActivity::class.java)
            intent.putExtra("name", name)
            itemView.context.startActivity(intent)
        }
    }

}